<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <script>

        // 

        // sum(10) = sum(9) + 10
        // sum(9) = sum(8) + 9
        // sum(8) = sum(7) + 8
        // ...
        // sum(1) = 1

        function sum(n) {
            if(n === 1) return 1 ;
            return sum(n-1) + n 
        }

        // 5 4 3 2 1 2 3 4 5 结束

        console.log(sum(5));
        
        // sum(5)
        // n = 5   sum(4) + 5
        //         sum(3)+4
        //         sum(2)+3
        //         sum(1)+2

    </script>
    
</body>
</html>